package servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class ContextServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        获得ServletContext对象
        ServletContext context = getServletContext();
        System.out.println(context);
//        1.获得初始化参数
        String initParameter = context.getInitParameter("driver");
        System.out.println(initParameter);
//        2.获得a b c d .txt的绝对路径
//        2.1获得a.txt
//        为什么的我classes中没有 class文件
        String a = context.getRealPath("");
        System.out.println(a);
//        2.2获得b.txt
//        为什么运行这后没有打印结果
        String b = context.getRealPath("/b.txt");
        System.out.println(b);

//        2.3获得c.txt
        String c = context.getRealPath("/html1/c.txt");
        System.out.println(c);
//        2.4获得d.txt
        String d = context.getRealPath("/WEB-INF/d.txt");
        System.out.println(d);
    }
}
